package com.heima.controller;

import com.heima.domain.dto.ExamineDTO;
import com.heima.domain.dto.ReviewDTO;
import com.heima.domain.pojo.Result;
import com.heima.domain.pojo.Review;
import com.heima.domain.query.ReviewQueryParam;
import com.heima.domain.vo.PageVo;
import com.heima.service.ReviewService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/review")
public class ReviewController {
    @Autowired
    private ReviewService reviewService;

    @GetMapping("/pagelist")
    @Operation(description = "来料分页")
    public Result page(ReviewQueryParam reviewQueryParam){
        PageVo vo = reviewService.pageList(reviewQueryParam);
        return Result.success(vo);
    }

    @PostMapping("/add")
    @Operation(description = "新增")
    public Review add(@RequestBody ReviewDTO dto){
        Review review = reviewService.add(dto);
        return review;
    }

    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Integer id){
        reviewService.removeById(id);
        return Result.success();
    }
    @PutMapping("/update")
    public Result update(@RequestBody Review review){
        reviewService.updateById(review);
        return Result.success();
    }

    @PutMapping("/examine")
    @Operation(description = "审核")
    public Review examine(@RequestBody ExamineDTO dto){
        Review review = reviewService.examine(dto);
        return review;
    }

}
